package com.sinochem.yunlian.ship.base.config;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import com.sinochem.yunlian.ship.common.filter.AuthRestInterceptor;
import com.sinochem.yunlian.ship.common.filter.RequestCountFilter;
import com.sinochem.yunlian.ship.base.method.SubjectMethodArgumentResolver;
import com.sinochem.yunlian.ship.common.handler.GlobalExceptionHandler;

/**
 * Created by ace on 2017/9/8.
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {


    
    @Bean
    SubjectMethodArgumentResolver getSubjectMethodArgumentResolver(){
        return new SubjectMethodArgumentResolver();
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        argumentResolvers.add(getSubjectMethodArgumentResolver());
    }


    @Bean
    GlobalExceptionHandler getGlobalExceptionHandler(){
        return new GlobalExceptionHandler();
    }
    

    private ArrayList<String> getExcludeCommonPathPatterns(){
        ArrayList<String> list = new ArrayList<>();
        String[] urls = {
                "/v2/api-docs",
                "/swagger-resources/**"
        };
        Collections.addAll(list,urls);
        return list;

    }
//
//    @Bean
//    public FilterRegistrationBean paraConvertFilterBean(){
//        FilterRegistrationBean registration = new FilterRegistrationBean();
//        //ParaConvertFilter paraConvertFilter = new ParaConvertFilter();
//        registration.setFilter(paraConvertFilter);
//        registration.setEnabled(true);
//        registration.addUrlPatterns("/*");
//        registration.setOrder(Ordered.LOWEST_PRECEDENCE);
//        return registration;
//    }
}
